package com.baizan.daka.mvp.model

import com.baizan.daka.Constants
import com.baizan.daka.mvp.model.bean.*
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.net.bean.*
import com.baizan.daka.util.SchedulerUtils
import com.hazz.kotlinmvp.net.BaseResponse
import com.hazz.kotlinmvp.net.RetrofitManager
import io.reactivex.Observable

class MeModel {

    fun userPackageDes(): Observable<BaseResponse<UserPackageDes>> =
        RetrofitManager.service.userPackageDes()
            .compose(SchedulerUtils.ioToMain())

    fun invitationCode(): Observable<BaseResponse<String>> =
        RetrofitManager.service.invitationCode()
            .compose(SchedulerUtils.ioToMain())

    fun modifyBank(
        id: Long, cardNo: String, bankName: String,
        bankBranch: String, bankUser: String
    ): Observable<BaseResponse<Any>> {
        val map = HashMap<String, Any>()
        map.put("id", id)
        map.put("cardNo", cardNo)
        map.put("bankName", bankName)
        map.put("bankBranch", bankBranch)
        map.put("bankUser", bankUser)
        return RetrofitManager.service.modifyBank(map)
            .compose(SchedulerUtils.ioToMain())
    }

    fun addBank(
        cardNo: String, bankName: String,
        bankBranch: String, bankUser: String
    ): Observable<BaseResponse<Any>> {
        val map = HashMap<String, String>()
        map.put("cardNo", cardNo)
        map.put("bankName", bankName)
        map.put("bankBranch", bankBranch)
        map.put("bankUser", bankUser)
        return RetrofitManager.service.addBank(map)
            .compose(SchedulerUtils.ioToMain())
    }

    fun applyShowCash(money: String, password: String): Observable<BaseResponse<Any>> {
        val map = HashMap<String, String>()
        map.put("amount", money)
        map.put("bankCode", password)
        return RetrofitManager.service.applyShowCash(map)
            .compose(SchedulerUtils.ioToMain())
    }

    fun getBankCard(): Observable<BaseResponse<BankCardInfoBean>> {

        return RetrofitManager.service.getBankDetail()
            .compose(SchedulerUtils.ioToMain())
    }


    fun getShowCashList(
        auditState: String?, page: Int
    ): Observable<BaseResponse<BasePageResponse<ShowCashBean>>> =
        RetrofitManager.service.getShowCashList(
                BasePageParam(
                    page, ShowCashRequest(auditState)
                )
            )
            .compose(SchedulerUtils.ioToMain())

    fun getCaplitalList(
        operationType: String?, page: Int
    ): Observable<BaseResponse<BasePageResponse<UserCaplitalDes>>> =
        RetrofitManager.service.capitalList(
                BasePageParam(
                    page, UserCaplitalDesRequestBean(operationType)
                )
            )
            .compose(SchedulerUtils.ioToMain())

    fun getTeamList(page: Int): Observable<BaseResponse<List<MyTeam>>> {
        return RetrofitManager.service.teamList(
            BasePageParam(
                page,
                UserTeamBean(Constants.userInfoBean?.account)
            )
        ).compose(SchedulerUtils.ioToMain())
    }

    fun getTeamDes(
        page: Int,
        teamLevel: Int
    ): Observable<BaseResponse<BasePageResponse<UserTeamDesBean>>> {
        return RetrofitManager.service.teamDetail(
            BasePageParam(
                page,
                UserTeamDesParam(teamLevel)
            )
        ).compose(SchedulerUtils.ioToMain())
    }

    fun getVipList(): Observable<BaseResponse<List<VipBean>>> {
        return RetrofitManager.service.vipList().compose(SchedulerUtils.ioToMain())
    }
}